* STATA Do file for Chapter 4, Mark R. Beissinger, The Revolutionary City  
version 14
clear all
set more off
log using Logfiles\chapter4.log, replace
* ============================================================================
* STATISTICAL RESULTS APPEARING IN CHAPTER 4
* STATA Do file for Chapter 4  
* Results reported in Chapter 4  
* Author: Mark R. Beissinger  
* Date:  January 2022  
* Princeton, NJ 
* =============================================================================
* BEFORE RUNNING, YOU MUST SET THE DEFAULT PATH FOR WHERE THE DATA
*   FILES RESIDE
* =============================================================================
* Before running, you must download the following packages for STATA:
*   looclass from http://fmwww.bc.edu/RePEc/bocode/l
*   mimrgns from http://fmwww.bc.edu/RePEc/bocode/m
* =============================================================================
* The following datafiles are used in this chapter:
*   States and episodes--statesandepisodes.dta 
*   Dataset of revolutionary episodes--revolutionaryeps.dta
*   Dataset of revolutionary episodes, multiple imputation (regime model)--revolutionaryepsmireg.dta
* 	Dataset of revolutionary episodes, multiple imputation (opposition model)--revolutionaryepsmiopp.dta
*	Dataset of revolutionary episodes, multiple imputation (combined model)--revolutionaryepsmicomb.dta
* =============================================================================
* Output produced:  Logfiles\chapter4.log
*					Logfiles\figure4_6a.pdf
*					Logfiles\figure4_6b.pdf
*					Logfiles\figure4_10a.pdf
*					Logfiles\figure4_10b.pdf
* 	--All output from this chapter has been combined into a single file and can 
*		be found in a pdf file (chapter4.pdf) in the "Outputfiles" folder
* =============================================================================


* ====================
* DATA FOR FIGURE 4.1
* ====================
use revolutionaryeps.dta
tab fiveyrperiodstr success if startyear>1899

* ======================================================================
* COUNT MODELS, EFFECT OF TIME ON NUMBER OF SUCCESSFUL REVOLUITIONS AND 
*   NUMBER OF FAILED REVOLUTIONS (WITH AND W/OUT COLLAPSE OF COMMUNISM
* ======================================================================
clear
use statesandepisodes.dta
* Failed cases
poisson failed year , vce(robust) irr nolog
estat gof
*  Result:  Failed goodness of fit test--must use negative binomial
nbreg failed year , vce(robust) irr nolog
* Successful cases
poisson success year , vce(robust) irr nolog
estat gof
*  Result:  Failed goodness of fit test--must use negative binomial
nbreg success year , vce(robust) irr nolog
* Without collapse of European communism cases
nbreg failnocommcoll year , vce(robust) irr nolog
nbreg succnocommcoll year , vce(robust) irr nolog

* ===========================
* PREDICTIONS OF COUNT MODEL
* ===========================
nbreg success year , vce(robust) irr nolog
predict succpred
list year succpred

* ====================
* DATA FOR FIGURE 4.2
* ====================
clear
use revolutionaryeps.dta
logit success startyear if startyear>1899, or nolog
margins, at(startyear=(1900 1905 1910 1915 1920 1925 1930 1935 1940 1945 1950 1955 1960 1965 1970 1975 1980 1985 1990 1995 2000 2005 2010 2015))

* ====================
* DATA FOR FIGURE 4.3
* ====================
logit success startyear urbandum if startprior1900==0, or nolog
margins, atmeans at(urbandum=(0 1))
logit success startyear urbancivic if startprior1900==0, or nolog
margins, atmeans at(urbancivic=1)
logit success startyear urbanleftist if startprior1900==0, or nolog
margins, atmeans at(urbanleftist=1)
logit success startyear ruralleftist if startprior1900==0, or nolog
margins, atmeans at(ruralleftist=1)
logit success startyear otherrev if startprior1900==0, or nolog
margins, atmeans at(otherrev=1)
* Excluding cases associated with collapse of European communism
logit success startyear urbancivic  if startyear>1899 & incgovcommunist==0 , or nolog
* Restricting sample to post-Cold War cases
logit success urbancivic  if  startyear>1984, or nolog


* ==================================================
* Regime characteristics and revolutionary outcomes
* ==================================================
* ===========================================================
* DATA FOR FIGURE 4.4 on effect of Polity scores on outcomes
* ===========================================================
* Testing for quadratic specification on complete sample
logit success politymin1 if startyear>1899 , or nolog
estat ic
logit success politymin1 politymin1sq if startyear>1899 , or nolog
estat ic
* Use Multiple imputation sample for all episodes, excluding colonies
clear
use revolutionaryepsmireg.dta
set seed 1234
* Outcomes for all episodes
mi estimate, post dots eform saving(miest, replace): logit success newpolitymin1 newpolitymin1sq if startyear>1899
mimrgns, at(newpolitymin1=-10 newpolitymin1sq=100) at(newpolitymin1=-9 newpolitymin1sq=81) at(newpolitymin1=-8 newpolitymin1sq=64) at(newpolitymin1=-7 newpolitymin1sq=49) at(newpolitymin1=-6 newpolitymin1sq=36) at(newpolitymin1=-5 newpolitymin1sq=25) at(newpolitymin1=-4 newpolitymin1sq=16) at(newpolitymin1=-3 newpolitymin1sq=9) at(newpolitymin1=-2 newpolitymin1sq=4) at(newpolitymin1=-1 newpolitymin1sq=1) at(newpolitymin1=0 newpolitymin1sq=0) at(newpolitymin1=1 newpolitymin1sq=1) at(newpolitymin1=2 newpolitymin1sq=4) at(newpolitymin1=3 newpolitymin1sq=9) at(newpolitymin1=4 newpolitymin1sq=16) at(newpolitymin1=5 newpolitymin1sq=25) at(newpolitymin1=6 newpolitymin1sq=36) at(newpolitymin1=7 newpolitymin1sq=49) at(newpolitymin1=8 newpolitymin1sq=64) at(newpolitymin1=9 newpolitymin1sq=81) at(newpolitymin1=10 newpolitymin1sq=100) predict(pr)
* Outcomes for all rural episodes
mi estimate, post dots eform saving(miest, replace): logit success newpolitymin1 newpolitymin1sq  if startyear>1899 & urbandum==0
mimrgns, at(newpolitymin1=-10 newpolitymin1sq=100) at(newpolitymin1=-9 newpolitymin1sq=81) at(newpolitymin1=-8 newpolitymin1sq=64) at(newpolitymin1=-7 newpolitymin1sq=49) at(newpolitymin1=-6 newpolitymin1sq=36) at(newpolitymin1=-5 newpolitymin1sq=25) at(newpolitymin1=-4 newpolitymin1sq=16) at(newpolitymin1=-3 newpolitymin1sq=9) at(newpolitymin1=-2 newpolitymin1sq=4) at(newpolitymin1=-1 newpolitymin1sq=1) at(newpolitymin1=0 newpolitymin1sq=0) at(newpolitymin1=1 newpolitymin1sq=1) at(newpolitymin1=2 newpolitymin1sq=4) at(newpolitymin1=3 newpolitymin1sq=9) at(newpolitymin1=4 newpolitymin1sq=16) at(newpolitymin1=5 newpolitymin1sq=25) at(newpolitymin1=6 newpolitymin1sq=36) at(newpolitymin1=7 newpolitymin1sq=49) at(newpolitymin1=8 newpolitymin1sq=64) at(newpolitymin1=9 newpolitymin1sq=81) at(newpolitymin1=10 newpolitymin1sq=100) predict(pr)
* Outcomes for all urban episodes
mi estimate, post dots eform saving(miest, replace): logit success newpolitymin1 newpolitymin1sq  if startyear>1899 & urbandum==1
mimrgns, at(newpolitymin1=-10 newpolitymin1sq=100) at(newpolitymin1=-9 newpolitymin1sq=81) at(newpolitymin1=-8 newpolitymin1sq=64) at(newpolitymin1=-7 newpolitymin1sq=49) at(newpolitymin1=-6 newpolitymin1sq=36) at(newpolitymin1=-5 newpolitymin1sq=25) at(newpolitymin1=-4 newpolitymin1sq=16) at(newpolitymin1=-3 newpolitymin1sq=9) at(newpolitymin1=-2 newpolitymin1sq=4) at(newpolitymin1=-1 newpolitymin1sq=1) at(newpolitymin1=0 newpolitymin1sq=0) at(newpolitymin1=1 newpolitymin1sq=1) at(newpolitymin1=2 newpolitymin1sq=4) at(newpolitymin1=3 newpolitymin1sq=9) at(newpolitymin1=4 newpolitymin1sq=16) at(newpolitymin1=5 newpolitymin1sq=25) at(newpolitymin1=6 newpolitymin1sq=36) at(newpolitymin1=7 newpolitymin1sq=49) at(newpolitymin1=8 newpolitymin1sq=64) at(newpolitymin1=9 newpolitymin1sq=81) at(newpolitymin1=10 newpolitymin1sq=100) predict(pr)
* Outcomes for all urban civic episodes
mi estimate, post dots eform saving(miest, replace): logit success newpolitymin1 newpolitymin1sq  if startyear>1899 & urbancivic==1
mimrgns, at(newpolitymin1=-10 newpolitymin1sq=100) at(newpolitymin1=-9 newpolitymin1sq=81) at(newpolitymin1=-8 newpolitymin1sq=64) at(newpolitymin1=-7 newpolitymin1sq=49) at(newpolitymin1=-6 newpolitymin1sq=36) at(newpolitymin1=-5 newpolitymin1sq=25) at(newpolitymin1=-4 newpolitymin1sq=16) at(newpolitymin1=-3 newpolitymin1sq=9) at(newpolitymin1=-2 newpolitymin1sq=4) at(newpolitymin1=-1 newpolitymin1sq=1) at(newpolitymin1=0 newpolitymin1sq=0) at(newpolitymin1=1 newpolitymin1sq=1) at(newpolitymin1=2 newpolitymin1sq=4) at(newpolitymin1=3 newpolitymin1sq=9) at(newpolitymin1=4 newpolitymin1sq=16) at(newpolitymin1=5 newpolitymin1sq=25) at(newpolitymin1=6 newpolitymin1sq=36) at(newpolitymin1=7 newpolitymin1sq=49) at(newpolitymin1=8 newpolitymin1sq=64) at(newpolitymin1=9 newpolitymin1sq=81) at(newpolitymin1=10 newpolitymin1sq=100) predict(pr)
* Outcomes for all social revolutionary episodes
mi estimate, post dots eform saving(miest, replace): logit success newpolitymin1 newpolitymin1sq  if startyear>1899 & leftist==1
mimrgns, at(newpolitymin1=-10 newpolitymin1sq=100) at(newpolitymin1=-9 newpolitymin1sq=81) at(newpolitymin1=-8 newpolitymin1sq=64) at(newpolitymin1=-7 newpolitymin1sq=49) at(newpolitymin1=-6 newpolitymin1sq=36) at(newpolitymin1=-5 newpolitymin1sq=25) at(newpolitymin1=-4 newpolitymin1sq=16) at(newpolitymin1=-3 newpolitymin1sq=9) at(newpolitymin1=-2 newpolitymin1sq=4) at(newpolitymin1=-1 newpolitymin1sq=1) at(newpolitymin1=0 newpolitymin1sq=0) at(newpolitymin1=1 newpolitymin1sq=1) at(newpolitymin1=2 newpolitymin1sq=4) at(newpolitymin1=3 newpolitymin1sq=9) at(newpolitymin1=4 newpolitymin1sq=16) at(newpolitymin1=5 newpolitymin1sq=25) at(newpolitymin1=6 newpolitymin1sq=36) at(newpolitymin1=7 newpolitymin1sq=49) at(newpolitymin1=8 newpolitymin1sq=64) at(newpolitymin1=9 newpolitymin1sq=81) at(newpolitymin1=10 newpolitymin1sq=100) predict(pr)

* =========================
* Results on regime types
* =========================
* Regime-types
* Use complete-case sample, as data available for all cases
clear
use revolutionaryeps.dta
* Test on regime-types, excluding colonies
logit success ib(#5).new2incumbgovtype if startyear>1899 & colony==0
estat classification
margins i.new2incumbgovtype
* Magnification of threat to all regime types if episode occurs in cities
logit success i.urbandum##ib(#5).new2incumbgovtype if startyear>1899 & colony==0, or nolog 
margins urbandum#new2incumbgovtype

*  Yrs leader in power
* Use imputed sample on all episodes, excluding colonies
clear
use revolutionaryepsmireg.dta
set seed 1234
* Estimate effect of yrs leader in power on success
mi estimate, post dots eform saving(miest, replace):  logit success newincumbpowerdur if startyear>1899
mimrgns, atmeans at(newincumbpowerdur=(0 5 10 15 20 25 30 35)) predict(pr)

*  Personalist regimes using Geddes et al. classification (since 1945 only, complete case sample)
* Use complete case sample
clear
use revolutionaryeps.dta
*  Analyze impact of personalist regime on success
logit success  gedincpersonal if startyear>1945, or nolog 
estat classification
margins, at(gedincpersonal=(0 1))
* T-test of yrs incumbent in power for regimes experiencing episode (personalist vs. other regimes)
ttest incumbpowerdur, by(gedincpersonal)

* ========================================================
* Results on age of incumbent leader in autocratic regimes
* ========================================================
* Use imputed sample on all episodes, excluding colonies
clear
use revolutionaryepsmireg.dta
set seed 1234
mi estimate, post dots eform saving(miest, replace): logit success newpolitymin1 newpolitymin1sq newincumbage if startyear>1899
mimrgns, at(newpolitymin1=-6 newpolitymin1sq=36 newincumbage=40) predict(pr)
mimrgns, at(newpolitymin1=-6 newpolitymin1sq=36 newincumbage=75) predict(pr)
mimrgns, at(newpolitymin1=6 newpolitymin1sq=36 newincumbage=75) predict (pr)
* Controlling for number of years incumbent in office
mi estimate, post dots eform saving(miest, replace): logit success newpolitymin1 newpolitymin1sq newincumbage newincumbpowerdur if startyear>1899
* Age of leader and yrs incumbent in power only moderately correlated
mi xeq 1: corr newincumbage newincumbpowerdur

* ====================================================================
* Results on level of development, oil, military spending per soldier
* ====================================================================
mi estimate, post dots eform saving(miest, replace): logit success newpolitymin1 newpolitymin1sq newincumbpowerdur newgdppcthl newlnoill newmilexpsold10tile civilwar newcivxmilexp if startyear>1899
mimrgns, atmeans at(newgdppcthl=(1 5 10)) predict(pr)
mimrgns, atmeans at((p10) newlnoill) predict(pr)
mimrgns, atmeans at((p90) newlnoill) predict(pr)
* T-tests of GDP per capita/oil and urban location of episodes
mi xeq 1: ttest newgdppcthl if startyear>1899, by(urbandum)
mi xeq 1: ttest newlnoill if startyear>1899, by(urbandum)
* Predictions for Haiti in 1946
mimrgns, atmeans at(newgdppcthl=1.046 newlnoill=0) predict(pr)
* Predictions for Azerbaijan in 2005
mimrgns, atmeans at(newgdppcthl=4.596682 newlnoill=9.660559) predict(pr)

* =============================================================================
* FIGURE 4.5 on interaction between military spending per soldier and civil war
* =============================================================================
* Interaction between military spending per soldier and civil war, controlling for GDP per capital and oil production
mi estimate, post dots eform saving(miest, replace): logit success newpolitymin1 newpolitymin1sq newincumbpowerdur newgdppcthl newlnoill newmilexpsold10tile civilwar newcivxmilexp if startyear>1899
mimrgns, atmeans at(civilwar=0 newmilexpsold10tile=1 newcivxmilexp=0) at(civilwar=0 newmilexpsold10tile=2 newcivxmilexp=0) at(civilwar=0 newmilexpsold10tile=3 newcivxmilexp=0) at(civilwar=0 newmilexpsold10tile=4 newcivxmilexp=0) at(civilwar=0 newmilexpsold10tile=5 newcivxmilexp=0) at(civilwar=0 newmilexpsold10tile=6 newcivxmilexp=0) at(civilwar=0 newmilexpsold10tile=7 newcivxmilexp=0) at(civilwar=0 newmilexpsold10tile=8 newcivxmilexp=0) at(civilwar=0 newmilexpsold10tile=9 newcivxmilexp=0) at(civilwar=0 newmilexpsold10tile=10 newcivxmilexp=0) predict(pr)
mimrgns, atmeans at(civilwar=1 newmilexpsold10tile=1 newcivxmilexp=1) at(civilwar=1 newmilexpsold10tile=2 newcivxmilexp=2) at(civilwar=1 newmilexpsold10tile=3 newcivxmilexp=3) at(civilwar=1 newmilexpsold10tile=4 newcivxmilexp=4) at(civilwar=1 newmilexpsold10tile=5 newcivxmilexp=5) at(civilwar=1 newmilexpsold10tile=6 newcivxmilexp=6) at(civilwar=1 newmilexpsold10tile=7 newcivxmilexp=7) at(civilwar=1 newmilexpsold10tile=8 newcivxmilexp=8) at(civilwar=1 newmilexpsold10tile=9 newcivxmilexp=9) at(civilwar=1 newmilexpsold10tile=10 newcivxmilexp=10) predict(pr)
* Favorability of revolutionary civil wars fought by conventional armies to opposition
clear
use revolutionaryeps.dta
logit success  conventional  if startyear>1899 & civilwar==1, or nolog

* ===============================================================
* Results on transnational revolutionary waves, political reform, 
*   electoral revolution, external war
* ===============================================================
* Bivariate relationships
clear
use revolutionaryepsmireg.dta
set seed 1234
mi estimate, post dots eform saving(miest, replace): logit success newrevwaveny  if startyear>1899
mimrgns,  at(newrevwaveny=(0 1)) predict(pr)
* Waves, for urban revolutions only
mi estimate, post dots eform saving(miest, replace): logit success newrevwaveny  if startyear>1899 & urbandum==1
* Without control vars
mi estimate, post dots eform saving(miest, replace): logit success newrevwaveny politreform electoralrev externalwar if startyear>1899
* With control vars
mi estimate, post dots eform saving(miest, replace): logit success newpolitymin1 newpolitymin1sq newincumbpowerdur newgdppcthl newmilexpsold10tile newrevwaveny politreform electoralrev externalwar startyear if startyear>1899
mimrgns, atmeans at(newrevwaveny=(0 1)) predict(pr)

* Matching to identify the independent treatment effect on the treated for 
*    mobilizing within a revolutionary wave
* Using propensity score matching on complete-case sample (n=272)
teffects psmatch (success) (newrevwaveny newpolitymin1 newpolitymin1sq  newgdppcthl   urbandum, logit ), atet nn(1) vce(robust)
* Balances checked before and after matching
tebalance summarize
* note: refitting the model using the generate() option
* 			Raw      Matched
* Number of obs =	272          192
* Treated obs   =	 96           96
* Control obs   =	176          96
*
*		  	Standardized differences	  	Variance ratio
*		       		Raw     Matched		  	Raw       Matched	
* newpolitymin1    -.246184    	.0922208	 .93064    1.148024
* newpolitymin1sq   .0770106   .0559115		.7938582   .7976309
* newgdppcthl      .5092342   .0915151		1.730871   .9817142
* urbandum     	    .741873          0		.6410007      1
*
* =============================
*  TABLE 4.1--regression table
* =============================
* Model 1
clear
use revolutionaryepsmireg.dta
mi estimate, post dots eform saving(miest, replace):  logit success c.newpolitymin1 newpolitymin1sq if startyear>1899
* Accuracy of predictions
mi predict xbsuccmi using miest, xb
generate prsuccmi = invlogit(xbsuccmi)
* Obtain accuracy of prediction
* Area under the ROC curve
roctab success xbsuccmi
drop xbsuccmi
drop prsuccmi
* AIC and BIC on common complete-case model
clear
use revolutionaryeps.dta
* create comparison sample for information criteria using model with smallest sample size 
quietly: logit success c.newpolitymin1##c.newpolitymin1 ib(#5).new2incumbgovtype newincumbage newincumbpowerdur newgdppcthl newlnoill civilwar##c.newmilexpsold10tile if startyear>1899 & colony==0 , or nolog
generate sample=e(sample)
quietly: logit success c.newpolitymin1##c.newpolitymin1 if startyear>1899 & sample==1, or nolog
estat ic
* True positive and false positive rates on complete-case sample
estat classification
drop sample

* Model 2
clear
use revolutionaryepsmireg.dta
mi estimate, post dots eform saving(miest, replace): logit success incgovmonarchy incgovmilitary incgovoneparty incgovcompauth incgovother if startyear>1899
* Accuracy of model
mi predict xbsuccmi using miest, xb
generate prsuccmi = invlogit(xbsuccmi)
* Obtain accuracy of prediction
* Area under the ROC curve
roctab success xbsuccmi
drop xbsuccmi
drop prsuccmi
* AIC and BIC on common complete-case model
clear
use revolutionaryeps.dta
* create comparison sample for information criteria using model with smallest sample size 
quietly: logit success c.newpolitymin1##c.newpolitymin1 ib(#5).new2incumbgovtype newincumbage newincumbpowerdur newgdppcthl newlnoill civilwar##c.newmilexpsold10tile if startyear>1899 & colony==0 , or nolog
generate sample=e(sample)
quietly: logit success ib(#5).new2incumbgovtype if startyear>1899 & sample==1, or nolog
estat ic
* True positive and false positive rates on complete-case sample
estat classification
drop sample

* Model 3
clear
use revolutionaryepsmireg.dta
mi estimate, post dots eform saving(miest, replace): logit success c.newpolitymin1 newpolitymin1sq incgovmonarchy incgovmilitary incgovoneparty incgovcompauth incgovother if startyear>1899
* Accuracy of model
mi predict xbsuccmi using miest, xb
generate prsuccmi = invlogit(xbsuccmi)
* Obtain accuracy of prediction
* Area under the ROC curve
roctab success xbsuccmi
drop xbsuccmi
drop prsuccmi
* AIC and BIC on common complete-case model
clear
use revolutionaryeps.dta
* create comparison sample for information criteria using model with smallest sample size 
quietly: logit success c.newpolitymin1##c.newpolitymin1 ib(#5).new2incumbgovtype newincumbage newincumbpowerdur newgdppcthl newlnoill civilwar##c.newmilexpsold10tile if startyear>1899 & colony==0 , or nolog
generate sample=e(sample)
quietly: logit success c.newpolitymin1##c.newpolitymin1 ib(#5).new2incumbgovtype if startyear>1899 & sample==1, nolog or
estat ic
* True positive and false positive rates on complete-case sample
estat classification
drop sample

* Model 4
clear
use revolutionaryepsmireg.dta
mi estimate, post dots eform saving(miest, replace): logit success newpolitymin1 newpolitymin1sq newincumbpowerdur newincumbage if startyear>1899
* Accuracy of model
mi predict xbsuccmi using miest, xb
generate prsuccmi = invlogit(xbsuccmi)
* Obtain accuracy of prediction
* Area under the ROC curve
roctab success xbsuccmi
drop xbsuccmi
drop prsuccmi
* AIC and BIC on common complete-case model
clear
use revolutionaryeps.dta
* create comparison sample for information criteria using model with smallest sample size 
quietly: logit success c.newpolitymin1##c.newpolitymin1 ib(#5).new2incumbgovtype newincumbage newincumbpowerdur newgdppcthl newlnoill civilwar##c.newmilexpsold10tile if startyear>1899 & colony==0 , or nolog
generate sample=e(sample)
quietly: logit success c.newpolitymin1##c.newpolitymin1 newincumbpowerdur newincumbage if startyear>1899 & sample==1, or nolog
estat ic
* True positive and false positive rates on complete-case sample
estat classification
drop sample

* Model 5
clear
use revolutionaryepsmireg.dta
mi estimate, post dots eform saving(miest, replace): logit success newpolitymin1 newpolitymin1sq newincumbpowerdur newgdppcthl newlnoill newmilexpsold10tile if startyear>1899
* Accuracy of model
mi predict xbsuccmi using miest, xb
generate prsuccmi = invlogit(xbsuccmi)
* Obtain accuracy of prediction
* Area under the ROC curve
roctab success xbsuccmi
drop xbsuccmi
drop prsuccmi
* AIC and BIC on common complete-case model
clear
use revolutionaryeps.dta
* create comparison sample for information criteria using model with smallest sample size 
quietly: logit success c.newpolitymin1##c.newpolitymin1 ib(#5).new2incumbgovtype newincumbage newincumbpowerdur newgdppcthl newlnoill civilwar##c.newmilexpsold10tile if startyear>1899 & colony==0 , or nolog
generate sample=e(sample)
quietly: logit success c.newpolitymin1##c.newpolitymin1 newincumbpowerdur newgdppcthl newlnoill newmilexpsold10tile if startyear>1899 & sample==1, nolog or
estat ic
* True positive and false positive rates on complete-case sample
estat classification
drop sample

* Model 6
clear
use revolutionaryepsmireg.dta
mi estimate, post dots eform saving(miest, replace): logit success newpolitymin1 newpolitymin1sq newincumbpowerdur newgdppcthl newlnoill newmilexpsold10tile civilwar newcivxmilexp if startyear>1899
* Accuracy of model
mi predict xbsuccmi using miest, xb
generate prsuccmi = invlogit(xbsuccmi)
* Obtain accuracy of prediction
* Area under the ROC curve
roctab success xbsuccmi
drop xbsuccmi
drop prsuccmi
* AIC and BIC on common complete-case model
clear
use revolutionaryeps.dta
* create comparison sample for information criteria using model with smallest sample size 
quietly: logit success c.newpolitymin1##c.newpolitymin1 ib(#5).new2incumbgovtype newincumbage newincumbpowerdur newgdppcthl newlnoill civilwar##c.newmilexpsold10tile newrevwaveny if startyear>1899 & colony==0 , or nolog
generate sample=e(sample)
quietly: logit success c.newpolitymin1##c.newpolitymin1 newincumbpowerdur newgdppcthl newlnoill i.civilwar##c.newmilexpsold10tile newrevwaveny if startyear>1899 & sample==1, nolog or
estat ic
* True positive and false positive rates on complete-case sample
estat classification
drop sample

* Model 7
clear
use revolutionaryepsmireg.dta
mi estimate, post dots eform saving(miest, replace): logit success newpolitymin1 newpolitymin1sq newincumbpowerdur revwaveny politreform electoralrev externalwar if startyear>1899
* Accuracy of model
mi predict xbsuccmi using miest, xb
generate prsuccmi = invlogit(xbsuccmi)
* Obtain accuracy of prediction
* Area under the ROC curve
roctab success xbsuccmi
drop xbsuccmi
drop prsuccmi
* AIC and BIC on common complete-case model
clear
use revolutionaryeps.dta
* create comparison sample for information criteria using model with smallest sample size 
quietly: logit success c.newpolitymin1##c.newpolitymin1 ib(#5).new2incumbgovtype newincumbage newincumbpowerdur newgdppcthl newlnoill civilwar##c.newmilexpsold10tile newrevwaveny if startyear>1899 & colony==0 , or nolog
generate sample=e(sample)
quietly:  logit success newpolitymin1 newpolitymin1sq newincumbpowerdur revwaveny politreform electoralrev externalwar if startyear>1899 & sample==1, nolog or
estat ic
* True positive and false positive rates on complete-case sample
estat classification
drop sample

* Model 8
clear
use revolutionaryepsmireg.dta
mi estimate, post dots eform saving(miest, replace): logit success newpolitymin1 newpolitymin1sq newincumbpowerdur newgdppcthl newlnoill newmilexpsold10tile civilwar newcivxmilexp newrevwaveny if startyear>1899
* Accuracy of model
mi predict xbsuccmi using miest, xb
generate prsuccmi = invlogit(xbsuccmi)
* Obtain accuracy of prediction
* Area under the ROC curve
roctab success xbsuccmi
drop xbsuccmi
drop prsuccmi
* AIC and BIC on common complete-case model
clear
use revolutionaryeps.dta
* create comparison sample for information criteria using model with smallest sample size 
quietly: logit success c.newpolitymin1##c.newpolitymin1 ib(#5).new2incumbgovtype newincumbage newincumbpowerdur newgdppcthl newlnoill civilwar##c.newmilexpsold10tile newrevwaveny if startyear>1899 & colony==0 , or nolog
generate sample=e(sample)
quietly: logit success c.newpolitymin1##c.newpolitymin1 newincumbpowerdur newgdppcthl newlnoill i.civilwar##c.newmilexpsold10tile newrevwaveny if startyear>1899 & sample==1, nolog or
estat ic
* True positive and false positive rates on complete-case sample
estat classification
drop sample

* Model 9--complete case analysis (based on Model 6, which has lowest BIC and AIC)
clear
use revolutionaryepsmireg.dta
* create comparison sample for information criteria using model with smallest sample size 
quietly: logit success c.newpolitymin1##c.newpolitymin1 ib(#5).new2incumbgovtype newincumbage newincumbpowerdur newgdppcthl newlnoill civilwar##c.newmilexpsold10tile if startyear>1899 & colony==0 , or nolog
generate sample=e(sample)
logit success c.newpolitymin1##c.newpolitymin1 newincumbpowerdur newgdppcthl newlnoill i.civilwar##c.newmilexpsold10tile if startyear>1899 & sample==1, nolog or
estat ic
* AUC
lroc success, nograph
* True positive and false positive rates on complete-case sample
estat classification

* =======================================
* FIGURE 4.6--ROC curves, by urban/rural
* =======================================
* Complete-case sample (based on Model 6)
* Figure 4.6a--regime factors, by urban/rural
clear
use revolutionaryeps.dta
quietly: logit success c.newpolitymin1##c.newpolitymin1 newincumbpowerdur newgdppcthl newlnoill i.civilwar##c.newmilexpsold10tile if startyear>1899 & colony==0, or nolog
generate sample=e(sample)
* Accuracy of model
predict xbsucc if sample==1, xb
roccomp success xbsucc if sample==1, by(urbandum) graph summary legend(position(6) order (1 2) cols(2)) ysize(6) xsize(6) plotregion(lcolor(black)) ylabel(, nogrid labsize(small)) xlabel(, nogrid labsize(small)) ytick(0(.1)1) xtick(0(.1)1) ylabel(0(.1)1) xlabel(0(.1)1) title({bf: 4.6A: Complete case sample} , size(medlarge)) ytitle({bf: True positive rate} , size(medsmall)) xtitle({bf: False positive rate} , size(medsmall)) rlopts(lpattern(dash)) plot1opts(msize(medlarge)) plot2opts(msize(medlarge))
* Saving graph to hard drive as figure4_6a.pdf
graph export Logfiles\figure4_6a.pdf, replace
drop xbsucc

* Imputed sample (based on Model 6)
* Figure 4.6b--regime factors, by urban/rural
clear
use revolutionaryepsmireg.dta
mi estimate, post dots eform saving(miest, replace): logit success newpolitymin1 newpolitymin1sq newincumbpowerdur newgdppcthl newlnoill newmilexpsold10tile civilwar newcivxmilexp if startyear>1899
* Accuracy of model
mi predict xbsuccmi using miest, xb
roccomp success xbsuccmi, by(urbandum) graph summary legend(position(6) order (1 2) cols(2)) ysize(6) xsize(6) plotregion(lcolor(black)) ylabel(, nogrid labsize(small)) xlabel(, nogrid labsize(small)) ytick(0(.1)1) xtick(0(.1)1) ylabel(0(.1)1) xlabel(0(.1)1) title({bf: 4.6B: Multiple imputation (20 samples)} , size(medlarge)) ytitle({it: True positive rate} , size(medsmall)) xtitle({it: False positive rate} , size(medsmall)) rlopts(lpattern(dash)) plot1opts(msize(medlarge)) plot2opts(msize(medlarge))
* Saving graph to hard drive as figure4_6a.pdf
graph export Logfiles\figure4_6b.pdf, replace
* Figures manipulated in Stata graph editor
* Figures combined in Stata graph editor and edited.
drop xbsuccmi

* ====================================================
* Movement characteristics and revolutionary outcomes
* ====================================================
* =================================================
* FIGURE 4.7--effect of participation on outcomes
* =================================================
* Using multiple imputation data for opposition tactics
clear
use revolutionaryepsmiopp.dta
set seed 1234
mi estimate, post dots eform saving(miest, replace): logit success lnparticnum if startyear>1899
mimrgns, at (lnparticnum = (6.907705527 9.210340372 9.903487553 10.30895266 10.59663473 10.81977828 11.00209984 11.15625052 11.28978191 11.40756495 11.51292546 11.60823564 11.69524702 11.77528973 11.8493977 11.91839057 11.98292909 12.04355372 12.10071213 12.15477935 12.20607265 12.25486281 12.30138283 12.34583459 12.3883942 12.4292162 12.46843691 12.50617724 12.54254488 12.5776362 12.61153775 12.64432758 12.67607627 12.70684793 12.7367009 12.76568843 12.79385931 12.82125828 12.84792653 12.87390202 12.89921983 12.92391244 12.94800999 12.97154049 12.99453001 13.01700286 13.03898177 13.06048797 13.08154138 13.10216067 13.12236338 13.142166 13.16158409 13.18063229 13.19932442 13.21767356 13.23569206 13.25339164 13.27078338 13.28787782 13.30468493)) expression(exp(predict(xb))/(1+exp(predict(xb))))
* Classificatory power of participation alone--complete case sample
clear
use revolutionaryeps.dta
logit success lnparticnum if startyear>1899, or nolog
estat classification

*  Median levels of participation, urban vs. rural revolts
sum particnum if urbandum==1 & startyear>1899, detail
sum particnum if urbandum==0 & startyear>1899, detail
* t-tests of literacy, schooling, newspaper readership, television ownership, and mobile phone ownership in urban vs. rural environments
ttest litpercbefrev if startyear>1899, by(urbandum)
ttest avgtotalyrsschool if startyear>1899, by(urbandum)
ttest newspercap if startyear>1899, by(urbandum)
ttest televispercap if startyear>1899, by(urbandum)
ttest mobilepercap if startyear>1899, by(urbandum)

* =================================================================
* FIGURE 4.8--effect of participation on outcomes in urban, rural, 
*    urban civic, and social revolutionary episodes
* =================================================================
* Multiple imputation sample
clear
use revolutionaryepsmiopp.dta
set seed 1234
mi estimate, post dots eform saving(miest, replace): logit success lnparticnum if startyear>1899 & urbandum==1
mimrgns, at (lnparticnum = (1 9.210340372 9.903487553 10.30895266 10.59663473 10.81977828 11.00209984 11.15625052 11.28978191 11.40756495 11.51292546 11.60823564 11.69524702 11.77528973 11.8493977 11.91839057 11.98292909 12.04355372 12.10071213 12.15477935 12.20607265 12.25486281 12.30138283 12.34583459 12.3883942 12.4292162 12.46843691 12.50617724 12.54254488 12.5776362 12.61153775 12.64432758 12.67607627 12.70684793 12.7367009 12.76568843 12.79385931 12.82125828 12.84792653 12.87390202 12.89921983 12.92391244 12.94800999 12.97154049 12.99453001 13.01700286 13.03898177 13.06048797 13.08154138 13.10216067 13.12236338 13.142166 13.16158409 13.18063229 13.19932442 13.21767356 13.23569206 13.25339164 13.27078338 13.28787782 13.30468493)) expression(exp(predict(xb))/(1+exp(predict(xb))))
mi estimate, post dots eform saving(miest, replace): logit success lnparticnum if startyear>1899 & urbandum==0
mimrgns, at (lnparticnum = (1 9.210340372 9.903487553 10.30895266 10.59663473 10.81977828 11.00209984 11.15625052 11.28978191 11.40756495 11.51292546 11.60823564 11.69524702 11.77528973 11.8493977 11.91839057 11.98292909 12.04355372 12.10071213 12.15477935 12.20607265 12.25486281 12.30138283 12.34583459 12.3883942 12.4292162 12.46843691 12.50617724 12.54254488 12.5776362 12.61153775 12.64432758 12.67607627 12.70684793 12.7367009 12.76568843 12.79385931 12.82125828 12.84792653 12.87390202 12.89921983 12.92391244 12.94800999 12.97154049 12.99453001 13.01700286 13.03898177 13.06048797 13.08154138 13.10216067 13.12236338 13.142166 13.16158409 13.18063229 13.19932442 13.21767356 13.23569206 13.25339164 13.27078338 13.28787782 13.30468493)) expression(exp(predict(xb))/(1+exp(predict(xb))))
mi estimate, post dots eform saving(miest, replace): logit success lnparticnum if startyear>1899 & urbancivic==1
mimrgns, at (lnparticnum = (1 9.210340372 9.903487553 10.30895266 10.59663473 10.81977828 11.00209984 11.15625052 11.28978191 11.40756495 11.51292546 11.60823564 11.69524702 11.77528973 11.8493977 11.91839057 11.98292909 12.04355372 12.10071213 12.15477935 12.20607265 12.25486281 12.30138283 12.34583459 12.3883942 12.4292162 12.46843691 12.50617724 12.54254488 12.5776362 12.61153775 12.64432758 12.67607627 12.70684793 12.7367009 12.76568843 12.79385931 12.82125828 12.84792653 12.87390202 12.89921983 12.92391244 12.94800999 12.97154049 12.99453001 13.01700286 13.03898177 13.06048797 13.08154138 13.10216067 13.12236338 13.142166 13.16158409 13.18063229 13.19932442 13.21767356 13.23569206 13.25339164 13.27078338 13.28787782 13.30468493)) expression(exp(predict(xb))/(1+exp(predict(xb))))
mi estimate, post dots eform saving(miest, replace): logit success lnparticnum if startyear>1899 & urbandum==1 & urbancivic==0
mimrgns, at (lnparticnum = (1 9.210340372 9.903487553 10.30895266 10.59663473 10.81977828 11.00209984 11.15625052 11.28978191 11.40756495 11.51292546 11.60823564 11.69524702 11.77528973 11.8493977 11.91839057 11.98292909 12.04355372 12.10071213 12.15477935 12.20607265 12.25486281 12.30138283 12.34583459 12.3883942 12.4292162 12.46843691 12.50617724 12.54254488 12.5776362 12.61153775 12.64432758 12.67607627 12.70684793 12.7367009 12.76568843 12.79385931 12.82125828 12.84792653 12.87390202 12.89921983 12.92391244 12.94800999 12.97154049 12.99453001 13.01700286 13.03898177 13.06048797 13.08154138 13.10216067 13.12236338 13.142166 13.16158409 13.18063229 13.19932442 13.21767356 13.23569206 13.25339164 13.27078338 13.28787782 13.30468493)) expression(exp(predict(xb))/(1+exp(predict(xb))))

* The effect of various tactics in urban and rural settings on the 
*    probability of success, controlling for participation
clear
use revolutionaryeps.dta
logit success lnpartic demonstrations strikes riots armed if startyear>1899 & urbandum==1
margins, atmeans at(demonstrations=1 riots=0  strikes=0 armed=0)
margins, atmeans at(demonstrations=0 riots=1  strikes=0 armed=0)
margins, atmeans at(demonstrations=0 riots=0  strikes=1 armed=0)
margins, atmeans at(demonstrations=0 riots=0  strikes=0 armed=1)
margins, atmeans at(demonstrations=0 riots=0  strikes=0 armed=0)
*  Civil war vs. other armed
logit success lnpartic demonstrations strikes riots armednocivwar civilwar if startyear>1899 & urbandum==1
margins, atmeans at(demonstrations=1 riots=0  strikes=0 armednocivwar=0 civilwar=0)
margins, atmeans at(demonstrations=0 riots=1  strikes=0 armednocivwar=0 civilwar=0)
margins, atmeans at(demonstrations=0 riots=0  strikes=1 armednocivwar=0 civilwar=0)
margins, atmeans at(demonstrations=0 riots=0  strikes=0 armednocivwar=1 civilwar=0)
margins, atmeans at(demonstrations=0 riots=0  strikes=0 armednocivwar=0 civilwar=1)
logit success demonstrations  riots civilwar if startyear>1899 & urbandum==0

* ===========================================================================
* FIGURE 4.9--effect of number of deaths on rev outcomes in urban/rural revs
* ===========================================================================
clear
use revolutionaryepsmiopp.dta
set seed 1234
mi estimate, post dots eform saving(miest, replace): logit success i.urbandum##c.deathtile10 if startyear>1899
mimrgns, at(urbandum=(0 1) deathtile10=(1 2 3 4 5 6 7 8 9 10)) predict(pr)

* ============================================================
* Contextual nature of the advantage of non-violent action in 
*   urban/rural episodes--beyond participation
* ============================================================
mi estimate, post dots eform saving(miest, replace): logit success lnparticnum lndeaths if startyear>1899 & urbandum==0
mi estimate, post dots eform saving(miest, replace): logit success lnparticnum lndeaths if startyear>1899 & urbandum==1

* ===============
* Movement goals
* ===============
clear
use revolutionaryeps.dta
logit success democrat leftist independ antimonarch ethnicorder islamist if startyear>1899, or nolog
estat classification
margins, at (democrat=1 leftist=0 antimonarch=0 independ=0 ethnicorder=0 islamist=0)
margins, at (democrat=0 leftist=0 antimonarch=1 independ=0 ethnicorder=0 islamist=0)
margins, at (democrat=0 leftist=1 antimonarch=0 independ=0 ethnicorder=0 islamist=0)
margins, at (democrat=0 leftist=0 antimonarch=0 independ=1 ethnicorder=0 islamist=0)
margins, at (democrat=0 leftist=0 antimonarch=0 independ=0 ethnicorder=1 islamist=0)
margins, at (democrat=0 leftist=0 antimonarch=0 independ=0 ethnicorder=0 islamist=1)
* Relationship between levels of participation and movement goals
reg lnparticnum democrat leftist independ antimonarch ethnicorder islamist if startyear>1899, vce(robust)
* Median peak participation by goals
sum particnum if startyear>1899 & democrat==1, detail
sum particnum if startyear>1899 & antimonarch==1, detail
sum particnum if startyear>1899 & leftist==1, detail
sum particnum if startyear>1899 & independ==1, detail
sum particnum if startyear>1899 & ethnicorder==1, detail
sum particnum if startyear>1899 & islamist==1, detail
* Effect of movement ideology and goals, independent of participation effects
clear
use revolutionaryepsmiopp.dta
mi estimate, post dots eform saving(miest, replace): logit success lnparticnum democrat leftist independ antimonarch ethnicorder islamist if startyear>1899
mi estimate, post dots eform saving(miest, replace): logit success  democrat leftist independ antimonarch ethnicorder islamist if startyear>1899 & urbandum==1
mi estimate, post dots eform saving(miest, replace): logit success  democrat leftist independ antimonarch ethnicorder islamist if startyear>1899 & urbandum==0
* Urban location of episodes by type of goals
clear
use revolutionaryeps.dta
logit urbandum democrat leftist independ antimonarch ethnicorder islamist if startyear>1899, or nolog
margins, at (democrat=1 leftist=0 antimonarch=0 independ=0 ethnicorder=0 islamist=0)
margins, at (democrat=0 leftist=0 antimonarch=1 independ=0 ethnicorder=0 islamist=0)
margins, at (democrat=0 leftist=1 antimonarch=0 independ=0 ethnicorder=0 islamist=0)
margins, at (democrat=0 leftist=0 antimonarch=0 independ=1 ethnicorder=0 islamist=0)
margins, at (democrat=0 leftist=0 antimonarch=0 independ=0 ethnicorder=1 islamist=0)
margins, at (democrat=0 leftist=0 antimonarch=0 independ=0 ethnicorder=0 islamist=1)
* Likelihood of civil war by type of goals
logit civilwar democrat leftist independ antimonarch ethnicorder islamist if startyear>1899, or nolog
margins, at (democrat=1 leftist=0 antimonarch=0 independ=0 ethnicorder=0 islamist=0)
margins, at (democrat=0 leftist=0 antimonarch=1 independ=0 ethnicorder=0 islamist=0)
margins, at (democrat=0 leftist=1 antimonarch=0 independ=0 ethnicorder=0 islamist=0)
margins, at (democrat=0 leftist=0 antimonarch=0 independ=1 ethnicorder=0 islamist=0)
margins, at (democrat=0 leftist=0 antimonarch=0 independ=0 ethnicorder=1 islamist=0)
margins, at (democrat=0 leftist=0 antimonarch=0 independ=0 ethnicorder=0 islamist=1)

* =====================================
* Forms of organization and leadership
* =====================================
logit success  coalitionleadership vanguard traditionalleadership paramilorg underground libmovement if startyear>1899, or nolog
estat classification
margins, at(coalitionleadership=1 vanguard=0 traditionalleadership=0 paramil=0 underground=0 libmovement=0)
margins, at(coalitionleadership=0 vanguard=0 traditionalleadership=1 paramil=0 underground=0 libmovement=0)
margins, at(coalitionleadership=0 vanguard=1 traditionalleadership=0 paramil=0 underground=0 libmovement=0)
margins, at(coalitionleadership=0 vanguard=0 traditionalleadership=0 paramil=0 underground=1 libmovement=0)
margins, at(coalitionleadership=0 vanguard=0 traditionalleadership=0 paramil=1 underground=0 libmovement=0)
margins, at(coalitionleadership=0 vanguard=0 traditionalleadership=0 paramil=0 underground=0 libmovement=1)
tab coalitionleadership urbandum if startyear>1899, row all
count if coalitionleadership==1
count if coalitionleadership==1 & (democrat==1 | antimonarch==1)
*  Independent effect of organizational forms aside from participation effects
clear
use revolutionaryepsmiopp.dta
set seed 1234
mi estimate, post dots eform saving(miest, replace): logit success lnparticnum coalitionleadership vanguard traditionalleadership paramilorg underground libmovement if startyear>1899
mi estimate, post dots eform saving(miest, replace): logit success lnparticnum coalitionleadership  if startyear>1899
mimrgns, atmeans at(coalitionleadership=(0 1)) predict(pr)
* Goals of liberation movements
clear
use revolutionaryeps.dta
tab libmovement democrat if startyear>1899, row chi
tab libmovement antimonarch if startyear>1899, row chi
tab libmovement leftist if startyear>1899, row chi
tab libmovement independ if startyear>1899, row chi
tab libmovement ethnicorder if startyear>1899, row chi

* =============================
*  TABLE 4.2--regression table
* =============================
* create comparison sample for information criteria using model with smallest sample size 
clear
use revolutionaryepsmiopp.dta
set seed 1234
quietly: logit success lnparticnum i.urbandum##c.deathtile10 democrat antimonarch if startyear>1899, or nolog
generate sample=e(sample)

* Model 1
* Multiple imputation model
mi estimate, post dots eform saving(miest, replace): logit success lnparticnum if startyear>1899
mi predict xbsuccmi using miest if startyear>1899, xb
generate prsuccmi = invlogit(xbsuccmi)
* Obtain accuracy of prediction
* Area under the ROC curve
roctab success xbsuccmi
drop xbsuccmi
drop prsuccmi
* AIC and BIC on common complete-case model
quietly:  logit success lnparticnum if startyear>1899 & sample==1, or nolog 
estat ic
* True positive and false positive rates on complete-case sample
estat classification

* Model 2
mi estimate, post dots eform saving(miest, replace): logit success i.urbandum##c.deathtile10 if startyear>1899
mi predict xbsuccmi using miest if startyear>1899, xb
generate prsuccmi = invlogit(xbsuccmi)
* Obtain accuracy of prediction
* Area under the ROC curve
roctab success xbsuccmi
drop xbsuccmi
drop prsuccmi
* AIC and BIC on common complete-case model
quietly: logit success i.urbandum##c.deathtile10 if startyear>1899 & sample==1, or nolog
estat ic
* True positive and false positive rates on complete-case sample
estat classification

* Model 3
logit success demonstrations strikes riots armednocivwar i.urbandum##i.civilwar if startyear>1899, or nolog
lroc , nograph
quietly: logit success demonstrations strikes riots armednocivwar i.urbandum##i.civilwar if startyear>1899 & sample, or nolog
estat classification
estat ic

* Model 4
logit success democrat leftist independ antimonarch ethnicorder islamist if startyear>1899, or nolog 
lroc , nograph
quietly: logit success democrat leftist independ antimonarch ethnicorder islamist if startyear>1899 & sample, or nolog
estat classification
estat ic

* Model 5
logit success coalitionleadership vanguard othpolpartylead traditionalleadership paramilorg underground libmovement if startyear>1899, or nolog
lroc , nograph
quietly:  logit success coalitionleadership vanguard othpolpartylead traditionalleadership paramilorg underground libmovement if startyear>1899 & sample, or nolog
estat classification
estat ic

* Model 6
mi estimate, post dots eform saving(miest, replace): logit success lnparticnum i.urbandum##c.deathtile10 demonstrations strikes civilwar democrat antimonarch coalitionleadership traditionalleadership if startyear>1899
mi predict xbsuccmi using miest if startyear>1899, xb
generate prsuccmi = invlogit(xbsuccmi)
* Obtain accuracy of prediction
* Area under the ROC curve
roctab success xbsuccmi
drop xbsuccmi
drop prsuccmi
* AIC and BIC on common complete-case model
quietly: logit success lnparticnum i.urbandum##c.deathtile10 demonstrations strikes civilwar democrat antimonarch coalitionleadership traditionalleadership if startyear>1899, or nolog
estat ic
* True positive and false positive rates on complete-case sample
estat classification

* Model 7
mi estimate, post dots eform saving(miest, replace): logit success lnparticnum i.urbandum##c.deathtile10 demonstrations strikes civilwar democrat antimonarch if startyear>1899
mi predict xbsuccmi using miest if startyear>1899, xb
generate prsuccmi = invlogit(xbsuccmi)
* Obtain accuracy of prediction
* Area under the ROC curve
roctab success xbsuccmi
drop xbsuccmi
drop prsuccmi
* AIC and BIC on common complete-case model
quietly: logit success lnparticnum i.urbandum##c.deathtile10 demonstrations strikes civilwar democrat antimonarch if startyear>1899, or nolog
estat ic
* True positive and false positive rates on complete-case sample
estat classification

* Likelihood ratio test between Model 7 and Model 1 (Model 1 has lower BIC; Model 7 has lower AIC)
* Model 1
quietly: logit success lnparticnum if startyear>1899 & sample, nolog or
estimates store mod1
* Model 7
quietly: logit success lnparticnum i.urbandum##c.deathtile10 demonstrations strikes civilwar democrat antimonarch if startyear>1899 & sample, or nolog
estimates store mod7
lrtest mod1 mod7
*  RESULT:  Superiority of Model 7 over nested Model 1 shown
drop _est_mod1 _est_mod7

* Likelihood ratio test between Model 7 and Model 2 (Model 2 has lower BIC; Model 7 has lower AIC)
* Model 2
quietly: logit success i.urbandum##c.deathtile10 if startyear>1899 & sample, nolog or
estimates store mod2
* Model 7
quietly: logit success lnparticnum i.urbandum##c.deathtile10 demonstrations strikes civilwar democrat antimonarch if startyear>1899 & sample, or nolog
estimates store mod7
lrtest mod2 mod7
*  RESULT:  Superiority of Model 7 over nested Model 2 shown
drop _est_mod2 _est_mod7
* clear the sample selection variable for comparing information criteria
drop sample

* ========================================================================
* FIGURE 4.10--ROC curves for opposition tactics, by urban/rural episodes
* ========================================================================
* Complete-case sample
* Figure 4.10a--opposition factors, by urban/rural
clear
use revolutionaryeps.dta
quietly: logit success lnparticnum i.urbandum##c.deathtile10 demonstrations strikes civilwar democrat antimonarch if startyear>1899, or nolog
generate sample=e(sample)
* Accuracy of model
predict xbsucc if sample==1, xb
roccomp success xbsucc if sample==1, by(urbandum) graph summary legend(position(6) order (1 2) cols(2)) ysize(6) xsize(6) plotregion(lcolor(black)) ylabel(, nogrid labsize(small)) xlabel(, nogrid labsize(small)) ytick(0(.1)1) xtick(0(.1)1) ylabel(0(.1)1) xlabel(0(.1)1) title({bf: 4.10a: Complete case sample} , size(medlarge)) ytitle({bf: True positive rate} , size(medsmall)) xtitle({bf: False positive rate} , size(medsmall)) rlopts(lpattern(dash)) plot1opts(msize(medlarge)) plot2opts(msize(medlarge))
graph export Logfiles\figure4_10a.pdf, replace
* Figure manipulated in Stata graph editor

* Imputed sample
* Figure 4.10b--regime factors, by urban/rural
clear
use revolutionaryepsmiopp.dta
mi estimate, post dots eform saving(miest, replace): logit success lnparticnum urbandum deathtile10 urbxdeathtile10 demonstrations strikes civilwar democrat antimonarch if startyear>1899
mi predict xbsuccmi using miest if startyear>1899, xb
roccomp success xbsuccmi, by(urbandum) graph summary legend(position(6) order (1 2) cols(2)) ysize(6) xsize(6) plotregion(lcolor(black)) ylabel(, nogrid labsize(small)) xlabel(, nogrid labsize(small)) ytick(0(.1)1) xtick(0(.1)1) ylabel(0(.1)1) xlabel(0(.1)1) title({bf: 4.10b: Multiple imputation (20 samples)} , size(medlarge)) ytitle({it: True positive rate} , size(medsmall)) xtitle({it: False positive rate} , size(medsmall)) rlopts(lpattern(dash)) plot1opts(msize(medlarge)) plot2opts(msize(medlarge))
graph export Logfiles\figure4_10b.pdf, replace
* Figures manipulated in Stata graph editor
* Figures combined in Stata graph editor and edited


* =============================================
* TABLE 4.3--combined models; regression table
* =============================================
* create comparison sample for information criteria using complete case model
clear
use revolutionaryepsmicomb.dta
set seed 1234
quietly: logit success lnparticnum urbandum deathtile10 urbxdeathtile10 demonstrations strikes democrat antimonarch newpolitymin1 newpolitymin1sq newincumbpowerdur newgdppcthl newlnoill newmilexpsold10tile civilwar newcivxmilexp if startyear>1899, or nolog
generate sample=e(sample)

* Opposition model
* Complete case sample
logit success lnparticnum urbandum deathtile10 urbxdeathtile10 demonstrations strikes civilwar democrat antimonarch if startyear>1899, or nolog
estat classification
lroc , nograph
* Leave-one-out cross-validated AUC
looclass success lnparticnum urbandum deathtile10 urbxdeathtile10 demonstrations strikes civilwar democrat antimonarch if startyear>1899, model (logit)
* AIC and BIC on common sample
quietly: logit success lnparticnum urbandum deathtile10 urbxdeathtile10 demonstrations strikes civilwar democrat antimonarch if startyear>1899 & sample==1, or nolog
estat ic
* Multiple imputation
mi estimate, post dots eform saving(miest, replace): logit success lnparticnum urbandum deathtile10 urbxdeathtile10 demonstrations strikes civilwar democrat antimonarch if startyear>1899
mi predict xbsuccmi using miest if startyear>1899, xb
roctab success xbsuccmi
drop xbsuccmi

* Regime model
* Complete-case sample
logit success newpolitymin1 newpolitymin1sq newincumbpowerdur newgdppcthl newlnoill newmilexpsold10tile civilwar newcivxmilexp if startyear>1899, or nolog
estat classification
lroc , nograph
* Leave-one-out cross-validated AUC
looclass success newpolitymin1 newpolitymin1sq newincumbpowerdur newgdppcthl newlnoill newmilexpsold10tile civilwar newcivxmilexp if startyear>1899, model (logit)
* AIC and BIC on common sample
quietly: logit success newpolitymin1 newpolitymin1sq newincumbpowerdur newgdppcthl newlnoill newmilexpsold10tile civilwar newcivxmilexp if startyear>1899 & sample, or nolog
estat ic
* Multiple imputation
mi estimate, post dots eform saving(miest, replace): logit success newpolitymin1 newpolitymin1sq newincumbpowerdur newgdppcthl newlnoill newmilexpsold10tile civilwar newcivxmilexp if startyear>1899
mi predict xbsuccmi using miest if startyear>1899, xb
roctab success xbsuccmi
drop xbsuccmi

* Combined model 1
* Complete-case sample
logit success lnparticnum urbandum deathtile10 urbxdeathtile10 demonstrations strikes democrat antimonarch newpolitymin1 newpolitymin1sq newincumbpowerdur newgdppcthl newlnoill newmilexpsold10tile civilwar newcivxmilexp if startyear>1899, or nolog
estat classification
lroc , nograph
* Leave-one-out cross-validated AUC--overfitting evident
looclass success lnparticnum urbandum deathtile10 urbxdeathtile10 demonstrations strikes democrat antimonarch newpolitymin1 newpolitymin1sq newincumbpowerdur newgdppcthl newlnoill newmilexpsold10tile civilwar newcivxmilexp if startyear>1899, model (logit)
* AIC and BIC on common sample
quietly: logit success lnparticnum urbandum deathtile10 urbxdeathtile10 demonstrations strikes democrat antimonarch newpolitymin1 newpolitymin1sq newincumbpowerdur newgdppcthl newlnoill newmilexpsold10tile civilwar newcivxmilexp if startyear>1899 & sample, or nolog
estat ic
* Multiple imputation
mi estimate, post dots eform saving(miest, replace): logit success lnparticnum urbandum deathtile10 urbxdeathtile10 demonstrations strikes democrat antimonarch newpolitymin1 newpolitymin1sq newincumbpowerdur newgdppcthl newlnoill newmilexpsold10tile civilwar newcivxmilexp if startyear>1899
mi predict xbsuccmi using miest if startyear>1899, xb
roctab success xbsuccmi
drop xbsuccmi

* Combined model 2 (reduced)
* Complete-case sample
logit success lnparticnum urbandum deathtile10 urbxdeathtile10 demonstrations newpolitymin1 newpolitymin1sq newincumbpowerdur newgdppcthl newlnoill newmilexpsold10tile if startyear>1899, or nolog
estat classification
lroc , nograph
* Leave-one-out cross-validated AUC
looclass success lnparticnum urbandum deathtile10 urbxdeathtile10 demonstrations  newpolitymin1 newpolitymin1sq newincumbpowerdur newgdppcthl newlnoill newmilexpsold10tile if startyear>1899, model (logit)
* AIC and BIC on common sample
quietly: logit success lnparticnum urbandum deathtile10 urbxdeathtile10 demonstrations  newpolitymin1 newpolitymin1sq newincumbpowerdur newgdppcthl newlnoill newmilexpsold10tile if startyear>1899 & sample, or nolog
estat ic
* Multiple imputation
mi estimate, post dots eform saving(miest, replace): logit success lnparticnum urbandum deathtile10 urbxdeathtile10 demonstrations newpolitymin1 newpolitymin1sq newincumbpowerdur newgdppcthl newlnoill newmilexpsold10tile if startyear>1899
mi predict xbsuccmi using miest if startyear>1899, xb
roctab success xbsuccmi
drop xbsuccmi

log close

erase miest.ster

clear
